import { http } from '../utils/request'
import type { CartItem } from '@/types/cart'

//加入购物车
export const addCartAPI = (data: { skuId: string, count: number }) => {
    return http({
        url: '/member/cart',
        method: 'POST',
        data
    })
}

//购物车列表
export const getCartListAPI = () => {
    return http<CartItem[]>({
        url: '/member/cart',
        method: 'GET'
    })
}

//删除/清空购物车单品
export const deleteCartAPI = (data: { ids: string[] }) => {
    return http({
        url: '/member/cart',
        method: 'DELETE',
        data
    })
}

//修改购物车单品
export const putMemberCartAPI = (skuId: string, data: { selected?: boolean, count?: number }) => {
    return http<CartItem>({
        url: `/member/cart/${skuId}`,
        method: 'PUT',
        data
    })
}

//购物车全选/取消全选
export const putMemberCartSelectedAPI = (data: { selected: boolean }) => {
    return http({
        url: '/member/cart/selected',
        method: 'PUT',
        data
    })
}